import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from "@dfeidao/atom-web/msg/nodejs";
import render from "@dfeidao/atom-web/render/render";
import s_get from '@dfeidao/atom-web/storage/get';

// import whoami from '@dfeidao/atom-web/msg/whoami';
// import { send_msg as url, get_user_info } from './config';

import p001 from './p001';
import p002 from './p002';
import p003 from './p003';

export default async function a005(fd: IFeidaoAiBrowserComponent, args: { usercode: string }) {
	//  调用事件
	const node1 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-zj="zj"]');
	node1.classList.remove('display-n');
	// console.log(args[0])
	const uscode = args;

	//
	render(fd, uscode, p002, 'p002', 'inner');
	// const user = await whoami(get_user_info);
	// console.log(user)
	const prid = await s_get('productid');

	const query = {
		productid: prid,
		usercode: uscode.usercode
	};
	const res = await nodejs<{ dataArray: object[] }>('consumer/zj-000004/consumer-find1', query);

	const p1 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	const p3 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	const tb = res.dataArray;
	const data = tb.map((v) => {
		return { ...v, v: JSON.stringify(v) };
	});
	if (res.dataArray.length === 0) {
		p1.classList.add('display-n');
		p3.classList.remove('display-n');
		render(fd, '', p001, 'p001', 'inner');
		render(fd, '', p003, 'p003', 'inner');
	} else {
		p3.classList.add('display-n');
		p1.classList.remove('display-n');
		render(fd, data, p001, 'p001', 'inner');
	}
}
